const RouterHook = require("../module/routerModule")
const router = RouterHook()
const swaggerJSDoc = require("swagger-jsdoc");
const path = require("path");

const swaggerDefinition = {
  info: {
    title: "选课系统",
    version: "1.0.0",
    description: "API",
  },
  host: "localhost:3000",//设置访问路径，之后文档中的访问接口都是以这个开头，如果访问不到的话可以看看路径拼接的对不对
  basePath: "/",
  //授权（自动传递token）
  securityDefinitions: {
    Authentication: {
      type: "apiKey",
      name: "Authentication",
      in: "header",
    },
  },
};
const options = {
  swaggerDefinition,
  apis: [path.join(__dirname, "*.js")], // 写有注解的router的存放地址，通过读取路由文件的注释生成json文档
};
const swaggerSpec = swaggerJSDoc(options);
// 访问/swagger.json返回生成的json
router.get("/swagger.json", async function (ctx) {
  ctx.set("Content-Type", "application/json");
  ctx.body = swaggerSpec;
}).noAuth()

module.exports = router;
